package com.dbpediamobile;

import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

/*
 * Autor: Camilo Verdugo
 * Activiy que gestiona el listado de favoritos
 * Obtiene el listado y permite la seleccion de cada item.
 */

public class Bookmarks extends Activity{
	ArrayList<BookmarksItemMap> todoItems;
	ArrayAdapter<BookmarksItemMap> aa;
	private static DBPediaMobile dbp;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
	  super.onCreate(savedInstanceState);
	  setContentView(R.layout.bookmarks); 
	  ListView bs = (ListView) findViewById(R.id.llbookmarks); 
	  todoItems = new ArrayList<BookmarksItemMap>();
	  dbp = new DBPediaMobile();
	  
	  MapaBD mbd = new MapaBD(this);
	  //mbd.deleteAll();
	  //mbd.insert(b);
	  todoItems = mbd.selectAll();	  
	  
	  aa = new ArrayAdapter<BookmarksItemMap>(this,android.R.layout.simple_list_item_1, todoItems);
	  bs.setAdapter(aa); 
	  bs.setOnItemClickListener(ItemEvent);
	}
	
	
	private OnItemClickListener ItemEvent = new OnItemClickListener() {
		Intent intent;
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
			for(int i=0;i<todoItems.size();i++){
				if(todoItems.get(i).name.equals(((BookmarksItemMap)arg0.getItemAtPosition(arg2)).toString())){
					dbp.bip = todoItems.get(i);
					intent = new Intent(Bookmarks.this,Mapa.class);
			        startActivity(intent);
			        break;
				}
			}
		}
		
    };
	
}
